library(devtools)
packageVersion("devtools")

# create a package outside other git repo or package
create_package('~/Documents/projects/regexcite')
# start a new session

setwd('~/Documents/projects/regexcite')
library(devtools)

# run once to initialize git repo
# use_git()

# add R script with func -----------
# open strsplit1.R in R/
# add func definition ONLY
use_r("strsplit1")

# also available in Build menu of Rstudio
# like interactively library(regexcite)
load_all()

(x <- "alfa,bravo,charlie,delta")
#> [1] "alfa,bravo,charlie,delta"
strsplit1(x, split = ",")
#> [1] "alfa"    "bravo"   "charlie" "delta"

# load_all() does not put strsplit1() in global env
exists("strsplit1", where = globalenv(), inherits = FALSE)
#> [1] FALSE

# R CMD check -----------
check()

use_mit_license()

# insert Roxygen docstring to func script
# and build document! ----------
document()

?strsplit1

# R CMD check again
check()

# install to local library ----------
install()

library(regexcite)

# initialize unit test with testthat ---------
use_testthat()

use_test("strsplit1")
#> ✔ Writing 'tests/testthat/test-strsplit1.R'.
#> ☐ Edit 'tests/testthat/test-strsplit1.R'.

# introduce stringr as deps of my package -----------
use_package('stringr')

# update func name and content
# also rename associated test file
# need to git commit on clean git state
rename_files("strsplit1", "str_split_one")

# update NAMESPACE with document()
document()

# use rmd to write readme with R code output!
use_readme_rmd()

# build md from rmd
build_readme()

# final check
check()
